package com.rcdz.mykotlindemo.view.customview.ohter;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

import com.rcdz.mykotlindemo.tools.EaseCubicInterpolator;
import com.rcdz.mykotlindemo.tools.MyLog;

/**
 * 简单的导航点
 */
public class TestView extends View {

    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f,1f).setDuration(2000);
    EaseCubicInterpolator jiasu = new EaseCubicInterpolator(.02f,.05f,.45f,1.13f);
    EaseCubicInterpolator jiansu = new EaseCubicInterpolator(.65f,-0.04f,.57f,2f);
    float left = 200;
    float left2 = 200;
    float top = 200;
    float right = 300;
    float right2 = 300;
    float bottom = 250;
    float x;
    Paint paint;
    public TestView(Context context) {
        this(context,null);
    }

    public TestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        valueAnimator.addUpdateListener(animation -> {
            x = (float) animation.getAnimatedValue();
            left2 = left+(left*jiansu.getInterpolation(x));
            right2 = right+(left* jiasu.getInterpolation(x));
            invalidate();
        });

    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.parseColor("#A416BC"));
        canvas.drawRoundRect(left2,top,right2,bottom,60,60,paint);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(1920, 1080);
    }
    public void start(){
        valueAnimator.cancel();
        valueAnimator.start();
    }
}
